
exports.main = async (event, context) => {
	// 引入七牛云JavaScript SDK
	const qiniu = require('qiniu');
	// 设置七牛云账号的AccessKey和SecretKey

	var accessKey = 'mGyop7FzyekB5l4KokIjx1zHRV6iIgYqay9RoIBK';
	var secretKey = 'oU7BzeY6Ubi8imTeKGC-tR-oDU5zcvWoRk3-iRZD';
	var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

	// 设置上传使用的Bucket
	const bucket = 'buer3301';
	try {
		// 从event中获取上传的图片信息，比如临时文件路径
		var options = {
			scope: bucket,
			expires: 7200,
			returnBody: '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}'
		};
		var putPolicy = new qiniu.rs.PutPolicy(options);
		var uploadToken = putPolicy.uploadToken(mac);
		return {
			code: 200,
			message: '获取token成功',
			data: uploadToken
		};
	} catch (error) {
		// 处理错误
		console.error(error);
		return {
			code: -1,
			message: '获取token失败',
			data: null
		};
	}
};